package cn.com.haopy.yue.ai.db.service.hos.impl;

import cn.com.haopy.yue.ai.db.entity.arisk.HOSAdmin;
import cn.com.haopy.yue.ai.db.mapper.arisk.HOSAdminMapper;
import cn.com.haopy.yue.ai.db.service.BaseServiceImpl;
import cn.com.haopy.yue.ai.db.service.hos.HOSAdminService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class HOSAdminServiceImpl extends BaseServiceImpl<HOSAdminMapper, HOSAdmin> implements HOSAdminService {
    @Override
    public List<HOSAdmin> findByName(String username) {
        LambdaQueryWrapper<HOSAdmin> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HOSAdmin::getUsername, username);

        return super.list(queryWrapper);
    }

    @Override
    public Page<HOSAdmin> querySelective(String username, Integer pageNo, Integer size, String sort, String order) {


        QueryWrapper<HOSAdmin> queryWrapper = new QueryWrapper<>();

        if (StringUtils.hasText(username)) {
            queryWrapper.lambda().like(HOSAdmin::getUsername, "%" + username + "%");
        }

        if (StringUtils.hasText(sort) && StringUtils.hasText(order)) {
            queryWrapper.orderBy(true, "asc".equals(order), sort);
        }

        Page<HOSAdmin> page = new Page<>(pageNo, size);

        return super.page(page, queryWrapper);
    }

    @Override
    public List<HOSAdmin> queryAll() {
        LambdaQueryWrapper<HOSAdmin> queryWrapper = new LambdaQueryWrapper<>();
        return super.list(queryWrapper);
    }
}
